Imports System
Imports System.Threading
Imports GeoFramework
Imports GeoFramework.Gps.Nmea
Imports GeoFramework.Gps.Emulators

''' <summary>
''' Reperesents a customized GPS device emulator.
''' </summary>
Public Class CustomEmulator
    Inherits NmeaEmulator

    ' The constructor specifies a name for the emulator.  This name is
    ' used as the name of the Thread when emulation is active.  The name
    ' should describe the device being emulated, and typically includes
    ' a support URL to assist developers.

    Public Sub New()
        MyBase.New("My custom device emulator (http://www.mycompany.com)")
    End Sub

    ' The OnEmulation method is responsible for generating the actual output 
    ' to send to listening clients.  This method is called on the emulation
    ' thread, so Thread.Sleep() statements are allowed and will not block the
    ' client application.  
    ' 
    ' For this example, we will send a single $GPRMC sentence describing the
    ' current position, speed, bearing and time to the client.  We will also
    ' send a second demo sentence to indicate that this is a custom emulator.
    ' 
    ' The NmeaEmulator class takes care of simulating realistic movement along
    ' a route.  This method should only generate output to the client, and not
    ' modify any information about the current location.

    Protected Overrides Sub OnEmulation()
        ' Build a $GPRMC sentence using the current simulated location, speed
        ' and bearing. 
        Dim Output As New GprmcSentence(Me.UtcDateTime, Me.IsFixed, Me.CurrentPosition, Me.Speed, _
                    Me.Bearing, Longitude.Empty)

        ' Send the output to any listening clients
        WriteToClient(Output)

        ' Also send a demo sentence just to prove this is working
        WriteToClient("It's easy to build a custom GPS device emulator." + ControlChars.CrLf)

        ' Sleep for one second before sending any more sentences
        Thread.Sleep(1000)
    End Sub
End Class

